package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.StrategyCommend;
import cn.wolfcode.luowowo.article.mapper.StrategyCommendMapper;
import cn.wolfcode.luowowo.article.service.IStraregyCommendService;
import cn.wolfcode.luowowo.common.query.QueryObject;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class StrategyCommendServiceImpl implements IStraregyCommendService {

    @Autowired
    private StrategyCommendMapper strategyCommendMapper;

    public PageInfo query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<StrategyCommend> list = strategyCommendMapper.selectForList(qo);
        return new PageInfo(list);
    }

    public AjaxResult save(StrategyCommend commend) {
        AjaxResult result = new AjaxResult();
        try {
            strategyCommendMapper.insert(commend);
        }catch (Exception e){
            e.printStackTrace();
            return result.mark("操作失败");
        }
        return result;
    }

    public List<StrategyCommend> listTop5() {
        return strategyCommendMapper.listTop5();
    }
}
